package com.atguigu.gulimall.ware.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @ ClassName WareWebMvcConfig
 * @ Description TODO
 * @ Author admin
 * @ Date 2021/3/31 18:06
 * @ Version 1.0
 */
@Configuration
public class WareWebMvcConfig implements WebMvcConfigurer {

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        //添加映射路径
        registry.addMapping("/api/**")
                //放行哪些原始域
                .allowedOrigins("*")
                //是否发送Cookie信息
                .allowCredentials(true)
                //放行哪些原始域(请求方式)
                .allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE")
                //放行哪些原始域(头部信息)
                .allowedHeaders("*","Content-Type,authorization","AccessToken")
                //暴露哪些头部信息（因为跨域访问默认不能获取全部头部信息）
                .exposedHeaders("Header1", "Header2")
                //跨域允许时间
                .maxAge(3600);
    }

}
